﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Diagnostics;
using System.Dynamic;
using System.Collections;
using System.Runtime.Serialization;

namespace TurboTemplate
{
    [DataContract(IsReference = true)]
    public class SchemaSet
    {
        [DataMember()]
        public List<SchemaTable> Tables { get; set; }
        [DataMember()]
        public List<SchemaStoredProcedure> Procedures { get; set; }

        public SchemaSet()
        {
            Tables = new List<SchemaTable>();
            Procedures = new List<SchemaStoredProcedure>();
        }
    }

    [DataContract(IsReference = true)]
    [DebuggerDisplay("{ParameterName}")]
    public class SchemaParameter : ICloneable
    {
        [DataMember()]
        public string ParameterName { get; set; }
        [DataMember()]
        public DbType DataType { get; set; }
        [DataMember()]
        public object Value { get; set; }
        [DataMember()]
        public bool UseNull { get; set; }
        [DataMember()]
        public int MaxLength { get; set; }

        public object Clone()
        {
            return (SchemaParameter)this.MemberwiseClone();
        }

    }

    [DataContract(IsReference = true)]
    [DebuggerDisplay("{SPECIFIC_NAME}")]
    public class SchemaStoredProcedure : ICloneable
    {
        [DataMember()]
        public string SPECIFIC_NAME { get; set; }
        [DataMember()]
        public bool ExecuteForData { get; set; }
        [DataMember()]
        public List<SchemaParameter> Parameters { get; set; }

        public SchemaStoredProcedure()
        {
            Parameters = new List<SchemaParameter>();
        }

        public SchemaStoredProcedure(string name)
        {
            Parameters = new List<SchemaParameter>();
            SPECIFIC_NAME = name;
        }

        public object Clone()
        {
            var ret = this.MemberwiseClone() as SchemaStoredProcedure;

            ret.Parameters = new List<SchemaParameter>();
            foreach (var item in this.Parameters)
            {
                ret.Parameters.Add((SchemaParameter)item.Clone());
            }

            return ret;
        }
    }

    [DataContract(IsReference = true)]
    [DebuggerDisplay("TABLE_NAME")]
    public class SchemaTable
    {
        [DataMember()]
        public string TABLE_NAME { get; set; }

        public SchemaTable()
        {
        }

        public SchemaTable(string name)
        {
            TABLE_NAME = name;
        }
    }
}
